﻿Imports System.Windows.Forms
Imports MySql.Data.MySqlClient
Public Class Dialog1
    Function mysql_connect()
        Try
            Dim connection As New MySqlConnection(Form1.connStr)
            connection.Open()
            connection.Close()
            Return 1
        Catch ex As Exception
            Return 0
        End Try
    End Function
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        My.Settings.sqlUsername = sqlUser.Text
        My.Settings.sqlPassword = sqlPass.Text
        My.Settings.DbHost = sqlHost.Text
        My.Settings.DbPort = sqlPort.Text
        My.Settings.sqlDatabase = sqlDb.Text
        My.Settings.Save()
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.Close()
    End Sub

    Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click

    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sqlPass.TextChanged

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sqlUser.TextChanged

    End Sub

    Private Sub Dialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form1.connStr = "Database=" + sqlDb.Text + ";Data Source=" + sqlHost.Text + ";Port=" + sqlPort.Text + ";User Id=" + sqlUser.Text + ";Password=" + sqlPass.Text
        Dim testConn As New MySqlConnection(Form1.connStr)
        If mysql_connect() = 1 Then
            MsgBox("Connection Successful!")
        Else
            MsgBox("Connection Failed.")
        End If
    End Sub
End Class
